package org.project.single.controller.back;

import cn.hutool.core.util.IdUtil;
import org.project.single.pojo.dto.auth.UserInfoAuthDto;
import org.project.single.pojo.ro.login.BackLoginRo;
import org.project.single.service.SysUserService;
import org.project.single.utils.LoginHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.stone.project.baseCommon.pojo.vo.R;

import javax.validation.Valid;

/**
 * 后台登录
 */
@RestController
@RequestMapping("/back/login")
public class BackLoginController {
    @Autowired
    private SysUserService sysUserService;

    /**
     * 登录
     * @return
     */
    @PostMapping("login")
    public R<String> login(@RequestBody @Valid BackLoginRo backLoginRo){
        UserInfoAuthDto userInfoAuthDto = new UserInfoAuthDto();
        userInfoAuthDto.setId(IdUtil.getSnowflake().nextIdStr());
        userInfoAuthDto.setUsername(backLoginRo.getUsername());
        return R.ok(sysUserService.backUserLogin(backLoginRo));
    }
}
